package com.itmyx.sys.service.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itmyx.base.util.UuidUtil;
import com.itmyx.base.util.String.StringUtil;
import com.itmyx.base.util.data.ParamData;
import com.itmyx.base.util.log.Logger;
import com.itmyx.base.util.log.ShowSqlUtil;
import com.itmyx.base.util.page.PageSize;
import com.itmyx.base.util.page.PaginationResult;
import com.itmyx.base.util.page.SimplePage;
import com.itmyx.sys.mapper.PermissionMapper;
import com.itmyx.sys.service.PermissionService;

/**
 * 功能描述
 * 
 * @类型名称 UserServiceImpl
 * @版本 1.0
 * @创建者 myx
 * @创建时间 2016年9月20日 下午3:36:40
 * @版权所有 @2016 ITMYX
 * @修改者 myx
 * @修改时间 2016年9月20日 下午3:36:40
 * @修改描述
 */
@Service
@Transactional
public class PermissionServiceImpl implements PermissionService {

	protected Logger logger = Logger.getLogger(this.getClass());
	
	private String nameSpace="com.itmyx.sys.mapper.PermissionMapper";

	@Autowired
	private PermissionMapper permissionMapper;
	
    @Autowired
    private SqlSessionFactory sqlSessionFactory;

	@Override
	public PaginationResult getList(ParamData param) {
		ShowSqlUtil.showMybatisSql(sqlSessionFactory,nameSpace,"selectListCount", param);//显示sql
		int count = permissionMapper.selectListCount(param);// 查询总数
		int pageSize = (int) (param.get("pageSize") == null ? PageSize.SIZE15.getSize() : StringUtil.strToInt((String) param.get("pageSize")));
		int pageNo = 0;
		if (null != param.get("pageNo")) {
			pageNo =  StringUtil.strToInt((String) param.get("pageNo"));
		}
		SimplePage page = new SimplePage(pageNo, count, pageSize);
		param.put("page", page);
		List<ParamData> list = permissionMapper.selectList(param);// 数据封装
		PaginationResult paginationResult = new PaginationResult(page, list);
		return paginationResult;
	}

	@Override
	public ParamData getById(ParamData param) {
		return permissionMapper.getById(param);
	}

	@Override
	public String add(ParamData param) {
		param.put("id", UuidUtil.get32UUID());
		permissionMapper.add(param);
		return param.getString("id");
	}

	@Override
	public boolean updateById(ParamData param) {
		boolean flag=false;
		if(!(StringUtil.strsIsNull(param.getString("id")))){
			permissionMapper.updateById(param);
			flag=true;
		}
		return flag;
	}

	@Override
	public boolean deleteById(ParamData param) {
		boolean flag=false;
		if(!(StringUtil.strsIsNull(param.getString("id")))){
			ShowSqlUtil.showMybatisSql(sqlSessionFactory,nameSpace,"deleteById", param);//显示sql
			permissionMapper.deleteById(param);
			flag=true;
		}
		return flag;
	}

}
